/** 
 * @CopyRight (c) 2012-2012
 * @Project <eshop>
 * @JDK_Version_Used:<JDK1.6>
 * @Description:TODO<描述用途>
 * @Title: CommonsServiceClient.java
 * @Author: <何俊>
 * @Author_of_Contact <E:azj1001@sina.com T:18651831939>
 * @Date 2012-11-10 下午4:56:45
 * @Modified_By: <修改人>
 * @Modified_of_Contact <修改人联系方式>
 * @Modified_Date <修改日期时间>
 * @Why & What is modified <修改原因描述>
 * @Version v1.00
 */
package com.e.buy.service;

import java.util.ArrayList;
import java.util.List;

import cn.commons.dbclient.Batchs;
import cn.commons.dbclient.exception.AzjDbClientException;
import cn.commons.email.exception.AzjEmailException;
import cn.commons.exception.proxy.AzjSqlExceptionProxy;
import cn.commons.query.ConditionBean;
import cn.commons.query.exception.AzjQueryBuilderException;
import cn.commons.stander.MailClient;

import com.e.buy.BuyTools;
import com.e.buy.bean.SqlRegister;
import com.e.buy.bean.Tree;
import com.e.buy.bean.back.manager.cmi_ad.CmiAdLocation;
import com.e.buy.bean.back.manager.cmi_ad.CmiAdType;
import com.e.buy.bean.back.manager.cmi_goods.CmiGoodsBrand;
import com.e.buy.bean.back.manager.cmi_goods.CmiGoodsCategroy;
import com.e.buy.bean.back.manager.cmi_goods.CmiGoodsProperties;
import com.e.buy.bean.back.manager.cmi_goods.CmiGoodsVariety;
import com.e.buy.bean.back.manager.cmi_news.CmiNewsType;
import com.e.buy.bean.back.manager.cmi_power.CmiAdminLog;
import com.e.buy.bean.back.manager.cmi_sigle.CmiSingleType;
import com.e.buy.bean.cmi_order.CmiOrder;
import com.e.buy.enums.Commons;
import com.e.buy.enums.Status;

/**
 * @Description:(通用的服务接口)
 * @author <何俊>
 * @date 2012-11-10 下午4:56:45
 * @version v1.0
 * @Other :@see #Files
 */
public class CommonsServiceClient extends BuyTools {

	/**
	 * 注册sql
	 * @Description:<函数描述>
	 * @title: initRegister
	 * @return void 返回类型
	 * @throws AzjDbClientException
	 */
	protected void initRegister() throws AzjDbClientException {
		//TODO total
		SqlRegister total = new SqlRegister()
			/* 权限管理*/
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE,service.getSql("sql", "cmi_power.role.total"))
			.register(Commons.BackProcess.ADMIN_INFO,service.getSql("sql", "admin.total"))
			.register(Commons.BackProcess.ADMIN_LOG,service.getSql("sql", "cmi_power.admin_log.total"))
			
			/* 商品管理*/
			.register(Commons.BackProcess.GOODS_CATEGROY,service.getSql("sql", "cmi_goods.categroy_list.total"))
			.register(Commons.BackProcess.GOODS_CATEGROY_PROPERTIES,service.getSql("sql", "cmi_goods.categroy_properties_list.total"))
			.register(Commons.BackProcess.GOODS_BRAND,service.getSql("sql", "cmi_goods.brand_list.total"))
			.register(Commons.BackProcess.GOODS,service.getSql("sql", "cmi_goods.goods_list.total"))
			/*新闻管理*/
			.register(Commons.BackProcess.NEWS,service.getSql("sql", "cmi_news.news_list.total"))
			.register(Commons.BackProcess.NEWS_TYPE,service.getSql("sql", "cmi_news.news_type_list.total"))
			
			/*单页管理*/
			.register(Commons.BackProcess.SINGLE,service.getSql("sql", "cmi_single.single_list.total"))
			.register(Commons.BackProcess.SINGLE_TYPE,service.getSql("sql", "cmi_single.single_type_list.total"))
			/*广告管理*/
			.register(Commons.BackProcess.AD,service.getSql("sql", "cmi_ad.ad_list.total"))
			.register(Commons.BackProcess.AD_TYPE,service.getSql("sql", "cmi_ad.ad_type_list.total"))
			.register(Commons.BackProcess.AD_LOC,service.getSql("sql", "cmi_ad.ad_loc_list.total"))
			/*订单管理*/
			.register(Commons.BackProcess.ORDER,service.getSql("sql", "cmi_order.order_list.total"))
			;
		
		//TODO pagin
		SqlRegister pagin = new SqlRegister()
			/* 权限管理*/
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE,service.getSql("sql", "cmi_power.role.pagin"))
			.register(Commons.BackProcess.ADMIN_INFO,service.getSql("sql", "admin.pagin"))
			.register(Commons.BackProcess.ADMIN_LOG,service.getSql("sql", "cmi_power.admin_log.pagin"))
			
			/* 商品管理*/
			.register(Commons.BackProcess.GOODS_CATEGROY,service.getSql("sql", "cmi_goods.categroy_list.pagin"))
			.register(Commons.BackProcess.GOODS_CATEGROY_PROPERTIES,service.getSql("sql", "cmi_goods.categroy_properties_list.pagin"))
			.register(Commons.BackProcess.GOODS_BRAND,service.getSql("sql", "cmi_goods.brand_list.pagin"))
			.register(Commons.BackProcess.GOODS,service.getSql("sql", "cmi_goods.goods_list.pagin"))
			/*新闻管理*/
			.register(Commons.BackProcess.NEWS,service.getSql("sql", "cmi_news.news_list.pagin"))
			.register(Commons.BackProcess.NEWS_TYPE,service.getSql("sql", "cmi_news.news_type_list.pagin"))
			
			/*单页管理*/
			.register(Commons.BackProcess.SINGLE,service.getSql("sql", "cmi_single.single_list.pagin"))
			.register(Commons.BackProcess.SINGLE_TYPE,service.getSql("sql", "cmi_single.single_type_list.pagin"))
			/*广告管理*/
			.register(Commons.BackProcess.AD,service.getSql("sql", "cmi_ad.ad_list.pagin"))
			.register(Commons.BackProcess.AD_TYPE,service.getSql("sql", "cmi_ad.ad_type_list.pagin"))
			.register(Commons.BackProcess.AD_LOC,service.getSql("sql", "cmi_ad.ad_loc_list.pagin"))
			/*订单管理*/
			.register(Commons.BackProcess.ORDER,service.getSql("sql", "cmi_order.order_list.pagin"))
			
			;
		
		//TODO head
		SqlRegister head = new SqlRegister()
			/* 权限管理*/
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE,service.getSql("sql", "cmi_power.role.head"))
			.register(Commons.BackProcess.ADMIN_INFO,service.getSql("sql", "admin.head"))
			.register(Commons.BackProcess.ADMIN_LOG,service.getSql("sql", "cmi_power.admin_log.head"))
			
			/* 商品管理*/
			.register(Commons.BackProcess.GOODS_CATEGROY,service.getSql("sql", "cmi_goods.categroy_list.head"))
			.register(Commons.BackProcess.GOODS_CATEGROY_PROPERTIES,service.getSql("sql", "cmi_goods.categroy_properties_list.head"))
			.register(Commons.BackProcess.GOODS_BRAND,service.getSql("sql", "cmi_goods.brand_list.head"))
			.register(Commons.BackProcess.GOODS,service.getSql("sql", "cmi_goods.goods_list.head"))
			/*新闻管理*/
			.register(Commons.BackProcess.NEWS,service.getSql("sql", "cmi_news.news_list.head")).register(Commons.BackProcess.NEWS,service.getSql("sql", "cmi_news.news_list.head"))
			.register(Commons.BackProcess.NEWS_TYPE,service.getSql("sql", "cmi_news.news_type_list.head"))
			/*单页管理*/
			.register(Commons.BackProcess.SINGLE,service.getSql("sql", "cmi_single.single_list.head"))
			.register(Commons.BackProcess.SINGLE_TYPE,service.getSql("sql", "cmi_single.single_type_list.head"))
			/*广告管理*/
			.register(Commons.BackProcess.AD,service.getSql("sql", "cmi_ad.ad_list.head"))
			.register(Commons.BackProcess.AD_TYPE,service.getSql("sql", "cmi_ad.ad_type_list.head"))
			.register(Commons.BackProcess.AD_LOC,service.getSql("sql", "cmi_ad.ad_loc_list.head"))
			/*订单管理*/
			.register(Commons.BackProcess.ORDER,service.getSql("sql", "cmi_order.order_list.head"))
			
			;
		
		//TODO sort
		SqlRegister sort = new SqlRegister()
			/* 权限管理*/
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE,service.getSql("sql", "cmi_power.role.sort"))
			.register(Commons.BackProcess.ADMIN_INFO,service.getSql("sql", "admin.sort"))
			.register(Commons.BackProcess.ADMIN_LOG,service.getSql("sql", "cmi_power.admin_log.sort"))
			
			/* 商品管理*/
			.register(Commons.BackProcess.GOODS_CATEGROY,service.getSql("sql", "cmi_goods.categroy_list.sort"))
			.register(Commons.BackProcess.GOODS_CATEGROY_PROPERTIES,service.getSql("sql", "cmi_goods.categroy_properties_list.sort"))
			.register(Commons.BackProcess.GOODS_BRAND,service.getSql("sql", "cmi_goods.brand_list.sort"))
			.register(Commons.BackProcess.GOODS,service.getSql("sql", "cmi_goods.goods_list.sort"))
			/*新闻管理*/
			.register(Commons.BackProcess.NEWS,service.getSql("sql", "cmi_news.news_list.sort"))
			.register(Commons.BackProcess.NEWS_TYPE,service.getSql("sql", "cmi_news.news_type_list.sort"))
			/*单页管理*/
			.register(Commons.BackProcess.SINGLE,service.getSql("sql", "cmi_single.single_list.sort"))
			.register(Commons.BackProcess.SINGLE_TYPE,service.getSql("sql", "cmi_single.single_type_list.sort"))
			/*广告管理*/
			.register(Commons.BackProcess.AD,service.getSql("sql", "cmi_ad.ad_list.sort"))
			.register(Commons.BackProcess.AD_TYPE,service.getSql("sql", "cmi_ad.ad_type_list.sort"))
			.register(Commons.BackProcess.AD_LOC,service.getSql("sql", "cmi_ad.ad_loc_list.sort"))
			/*订单管理*/
			.register(Commons.BackProcess.ORDER,service.getSql("sql", "cmi_order.order_list.sort"))
			
			;
		
		//TODO add
		SqlRegister add = new SqlRegister()
			.register(Commons.BackProcess.ADMIN_LOG,service.getSql("sql", "admin.log"))
			/* 权限管理*/
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE,service.getSql("sql", "cmi_power.role.add"))
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE_POWER,service.getSql("sql", "cmi_power.role.power.add"))
			.register(Commons.BackProcess.ADMIN_INFO,service.getSql("sql", "cmi_admin_info.add"))
			.register(Commons.BackProcess.ADMIN_INFO_POWER,service.getSql("sql", "cmi_admin_info.power.add"))
			
			/* 商品管理*/
			.register(Commons.BackProcess.GOODS_CATEGROY,service.getSql("sql", "cmi_goods.categroy_list.add"))
			.register(Commons.BackProcess.GOODS_CATEGROY_PROPERTIES,service.getSql("sql", "cmi_goods.categroy_properties_list.add"))
			.register(Commons.BackProcess.GOODS_BRAND,service.getSql("sql", "cmi_goods.brand_list.add"))
			.register(Commons.BackProcess.GOODS_VARIETY,service.getSql("sql", "cmi_goods.variety_list.add"))
			.register(Commons.BackProcess.GOODS,service.getSql("sql", "cmi_goods.goods_edit_add"))
			/*新闻管理*/
			.register(Commons.BackProcess.NEWS,service.getSql("sql", "cmi_news.news_list.add"))
			.register(Commons.BackProcess.NEWS_TYPE,service.getSql("sql", "cmi_news.news_type_list.add"))
			
			/*单页管理*/
			.register(Commons.BackProcess.SINGLE,service.getSql("sql", "cmi_single.single_list.add"))
			.register(Commons.BackProcess.SINGLE_TYPE,service.getSql("sql", "cmi_single.single_type_list.add"))
			/*广告管理*/
			.register(Commons.BackProcess.AD,service.getSql("sql", "cmi_ad.ad_list.add"))
			.register(Commons.BackProcess.AD_TYPE,service.getSql("sql", "cmi_ad.ad_type_list.add"))
			.register(Commons.BackProcess.AD_LOC,service.getSql("sql", "cmi_ad.ad_loc_list.add"))
			;
	
		//TODO modify
		SqlRegister modify = new SqlRegister()
			.register(Commons.BackProcess.ADMIN_LOGIN,service.getSql("sql", "admin.update"))
			.register(Commons.BackProcess.ADMIN_FORGETPWD,service.getSql("sql", "admin.forgetpwd.update"))
			.register(Commons.BackProcess.ADMIN_MODIFY_PERSONER,service.getSql("sql", "admin.modify.personer"))
			/* 权限管理*/
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE,service.getSql("sql", "cmi_power.role.update"))
			.register(Commons.BackProcess.ADMIN_INFO,service.getSql("sql", "cmi_admin_info.update"))
			
			/* 商品管理*/
			.register(Commons.BackProcess.GOODS_CATEGROY,service.getSql("sql", "cmi_goods.categroy_list.modify"))
			.register(Commons.BackProcess.GOODS_CATEGROY_PROPERTIES,service.getSql("sql", "cmi_goods.categroy_properties_list.modify"))
			.register(Commons.BackProcess.GOODS_BRAND,service.getSql("sql", "cmi_goods.brand_list.modify"))
			.register(Commons.BackProcess.GOODS_VARIETY,service.getSql("sql", "cmi_goods.variety_list.modify"))
			/*新闻管理*/
			.register(Commons.BackProcess.NEWS,service.getSql("sql", "cmi_news.news_list.modify"))
			.register(Commons.BackProcess.NEWS_TYPE,service.getSql("sql", "cmi_news.news_type_list.modify"))
			
			/*单页管理*/
			.register(Commons.BackProcess.SINGLE,service.getSql("sql", "cmi_single.single_list.modify"))
			.register(Commons.BackProcess.SINGLE_TYPE,service.getSql("sql", "cmi_single.single_type_list.modify"))
			/*广告管理*/
			.register(Commons.BackProcess.AD,service.getSql("sql", "cmi_ad.ad_list.modify"))
			.register(Commons.BackProcess.AD_TYPE,service.getSql("sql", "cmi_ad.ad_type_list.modify"))
			.register(Commons.BackProcess.AD_LOC,service.getSql("sql", "cmi_ad.ad_loc_list.modify"))
			;
		
		//TODO remove
		SqlRegister remove = new SqlRegister()
			 /* 权限管理*/
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE,service.getSql("sql", "cmi_power.role.remove"))
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE_POWER,service.getSql("sql", "cmi_power.role.power.remove"))
			.register(Commons.BackProcess.ADMIN_INFO,service.getSql("sql", "cmi_admin_info.remove"))
			.register(Commons.BackProcess.ADMIN_INFO_POWER,service.getSql("sql", "cmi_admin_info.power.remove"))
			.register(Commons.BackProcess.ADMIN_LOG,service.getSql("sql", "cmi_power.admin_log.remove"))
			
			/* 商品管理*/
			.register(Commons.BackProcess.GOODS_CATEGROY,service.getSql("sql", "cmi_goods.categroy_list.remove"))
			.register(Commons.BackProcess.GOODS_CATEGROY_PROPERTIES,service.getSql("sql", "cmi_goods.categroy_properties_list.remove"))
			.register(Commons.BackProcess.GOODS_BRAND,service.getSql("sql", "cmi_goods.brand_list.remove"))
			.register(Commons.BackProcess.GOODS_VARIETY,service.getSql("sql", "cmi_goods.variety_list.remove"))
			/*新闻管理*/
			.register(Commons.BackProcess.NEWS,service.getSql("sql", "cmi_news.news_list.remove"))
			.register(Commons.BackProcess.NEWS_TYPE,service.getSql("sql", "cmi_news.news_type_list.remove"))
			
			/*单页管理*/
			.register(Commons.BackProcess.SINGLE,service.getSql("sql", "cmi_single.single_list.remove"))
			.register(Commons.BackProcess.SINGLE_TYPE,service.getSql("sql", "cmi_single.single_type_list.remove"))
			/*广告管理*/
			.register(Commons.BackProcess.AD,service.getSql("sql", "cmi_ad.ad_list.remove"))
			.register(Commons.BackProcess.AD_TYPE,service.getSql("sql", "cmi_ad.ad_type_list.remove"))
			.register(Commons.BackProcess.AD_LOC,service.getSql("sql", "cmi_ad.ad_loc_list.remove"))
			;
		
		//TODO ObjList
		SqlRegister objList = new SqlRegister()
			 /* 查询所有角色选择框数据*/
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE,service.getSql("sql", "cmi_power.role.combox.list"))
			.register(Commons.BackProcess.ADMIN_LOG,service.getSql("sql", "cmi_power.admin_log.iplist"))
			.register(Commons.BackProcess.GOODS_CATEGROY,service.getSql("sql", "cmi_goods.categroy_list.objectlist"))
			.register(Commons.BackProcess.GOODS_CATEGROY_PROPERTIES,service.getSql("sql", "cmi_goods.categroy_properties_list.objectlist"))
			.register(Commons.BackProcess.GOODS_VARIETY,service.getSql("sql", "cmi_goods.variety_list.objectlist"))
			.register(Commons.BackProcess.GOODS_BRAND,service.getSql("sql", "cmi_goods.brand_list.objectlist"))
			.register(Commons.BackProcess.NEWS,service.getSql("sql", "cmi_news.news_list.varietylist"))
			.register(Commons.BackProcess.SINGLE,service.getSql("sql", "cmi_single.single_list.typelist"))
			/*广告管理*/
			.register(Commons.BackProcess.AD_TYPE,service.getSql("sql", "cmi_ad.ad_list.typelist"))
			.register(Commons.BackProcess.AD_LOC,service.getSql("sql", "cmi_ad.ad_list.loclist"))
			
			;
		
		//TODO tree
		SqlRegister tree = new SqlRegister()
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE,service.getSql("sql", "cmi_power.role.system.tree"))
			.register(Commons.BackProcess.ADMIN_POWER_CMI_ROLE_POWER,service.getSql("sql", "cmi_power.role.power.system.tree"))
			.register(Commons.BackProcess.ADMIN_SYSTEM,service.getSql("sql", "cmi_admin_info.admin.system.tree"))
			.register(Commons.BackProcess.ADMIN_INFO,service.getSql("sql", "cmi_admin_info.power.system.tree"))
			;

		register = new SqlRegister()
			.register(Status.ADD, add)
			.register(Status.MODIFY, modify)
			.register(Status.REMOVE, remove)
			.register(Status.TOTAL, total)
			.register(Status.HEAD, head)
			.register(Status.PAGIN, pagin)
			.register(Status.SORT, sort)
			.register(Status.TREE, tree)
			.register(Status.OBJECT_LIST, objList)
			;
	}

	/**
	 * @Description:<获取操作类型的sql语句>
	 * @title: getEnumSql
	 * @param e
	 * @param state
	 * @return String 返回类型
	 * @throws
	 */
	@Override
	public String getEnumSql(Enum<?> e, Status state) {
		Object sql = null;
		try {
			if (register == null) {
				initRegister();
			}
			sql = ((SqlRegister) register.get(state)).get(e);
			if (sql == null || sql.equals("")) {
				log4j.error("SQL Has Not being Register");
			}
		} catch (Exception ex) {
			sql = null;
		}
		return (sql == null) ? null : sql.toString();
	}

	/**
	 * @Description:<通过服务器发送邮箱给知道人员列表>
	 * @title: sendEmail
	 * @param toAddress
	 * @return boolean 返回类型
	 * @throws
	 */
	public boolean sendEmail(String subject,String content,String... toAddress) {
		String client = this.getWebProperties("web", "email.mail.client");
		String fromAddress = this.getWebProperties("web", "email.from");
		String userName = this.getWebProperties("web", "email.user");
		String password = this.getWebProperties("web", "email.pws");
		MailClient c = Commons.getMailClient(client);
		if (c == null) {
			log4j.error("服务器邮件类型未定义!");
			return false;
		}
		try {
			service.SendEMail(c, fromAddress, userName, password, subject, content, false, toAddress);
			return true;
		} catch (AzjEmailException e) {
			log4j.error(e);
			return false;
		}
	}

	/**
	 * @Description:<编辑admin操作信息，并记录操作日志>
	 * @title: editAdminWithLog
	 * @param e :编辑状态
	 * @param state ：做的操作
	 * @param editArgs：操作中涉及到的参数
	 * @param doWhatMsg :日志记录下做什么
	 * @param who ：哪个管理员：管理员uuid
	 * @return void 返回类型
	 * @throws Exception 
	 */
	public boolean editAdminWithLog(Commons.BackProcess e,Status state, Object[] editArgs,String doWhatMsg,int who) throws Exception {
		boolean b = false;
		String sql = null;
		String sqlLog = null;
		List<Object[]> args = null;
		try {
			//获取执行sql
			sql = this.getEnumSql(e, state);
			sqlLog = this.getEnumSql(Commons.BackProcess.ADMIN_LOG, Status.ADD);
			
			if(sql != null && sqlLog != null) {
				List<Batchs> batchs = new ArrayList<Batchs>();
				
				//写入管理员操作
				args = new ArrayList<Object[]>();
				args.add(editArgs);
				batchs.add(new Batchs(sql, args));
				
				//写入日志
				args = new ArrayList<Object[]>();
				args.add(new Object[]{doWhatMsg,who});
				batchs.add(new Batchs(sqlLog, args));
				
				service.executeBatchSQL(batchs);
				b = true;
			}
		} catch (Exception ex) {
			AzjSqlExceptionProxy p = new AzjSqlExceptionProxy(ex);
			int errorCode = p.getErrorCode();
			//唯一键存在重复项
			if(errorCode == 1062) {
				throw p;
			}
			log4j.error("EditAdminWithLog Error:" + ex);
			b = false;
//			throw new Exception(ex.getMessage());
		}
		return b;
	}
	
	/**
	 * @Description:<记录管理员操作日志>
	 * @title: noteAdminLog
	 * @param doWhatMsg
	 * @param who
	 * @return boolean 返回类型
	 * @throws
	 */
	public boolean noteAdminLog(String doWhatMsg,int who) {
		boolean b = false;
		String sql = null;
		try{
			sql = this.getEnumSql(Commons.BackProcess.ADMIN_LOG, Status.ADD);
			service.executeSQL(sql, doWhatMsg,who);
		} catch (Exception ex) {
			log4j.error("NoteAdminLog Error:" + ex);
			b = false;
		}
		return b;
	}
	
	@SuppressWarnings("unchecked")
	public List<Tree> queryTree(Enum<?> e,Status state,List<ConditionBean> beans,Object... args) throws AzjQueryBuilderException {
		String sql = this.getEnumSql(e, state);
		List<Tree> ls = (List<Tree>) service.queryForList(sql, Tree.class, beans, args);
		List<Tree> supers = new ArrayList<Tree>();
		for (Tree c : ls) {
			for (Tree s : ls) {
				if (s.getId().equals(c.getSuperNm())) {
					s.getChildren().add(c);
					supers.add(c);
				}
			}
		}
		ls.removeAll(supers);
		return ls;
	}
	
	/**
	 * @Description:<统一查询对象集合>
	 * @title: queryObjectList
	 * @param st
	 * @param qy
	 * @return List<?> 返回类型
	 * @throws
	 */
	@SuppressWarnings("unchecked")
	public List<?> queryObjectList(String st,String qy) {
		Class<?> c = null;
		List<?> ls = null;
		String sql = null;
		boolean hasDone = false;
		Object[] args = new Object[0];
		Status state = Status.OBJECT_LIST;
		Commons.BackProcess e = Commons.BackProcess.DEFAULT;
		List<ConditionBean> beans = new ArrayList<ConditionBean>();
		
		try { 
			e = Commons.getBackProcess(st);
			sql = this.getEnumSql(e, state);
			switch (e) {
			case ADMIN_POWER_CMI_ROLE:
				c = Tree.class;
				break;
			case ADMIN_LOG:
				c = CmiAdminLog.class;
				break;
			case GOODS_CATEGROY:
				hasDone = true;
				c = CmiGoodsCategroy.class;
				List<CmiGoodsCategroy> rt = (List<CmiGoodsCategroy>) service.queryForList(sql, c, beans, args);
				CmiGoodsCategroy all = new CmiGoodsCategroy();
				all.setUuid(0);
				all.setCategroy("所有商品类型");
				rt.add(0, all);
				ls = rt;
				break;
			case GOODS_CATEGROY_PROPERTIES:
				hasDone = true;
				c = CmiGoodsProperties.class;
				beans.add(new ConditionBean("categroyId", "=", "?", qy, null));
				List<CmiGoodsProperties> clist = (List<CmiGoodsProperties>) service.queryForList(sql, c, beans, args);
				CmiGoodsProperties p = new CmiGoodsProperties();
				p.setUuid("0");
				p.setProName("请筛选属性");
				clist.add(0, p);
				ls = clist;
				break;
			case GOODS_VARIETY:
				hasDone = true;
				c = CmiGoodsVariety.class;
				List<CmiGoodsVariety> vl = (List<CmiGoodsVariety>) service.queryForList(sql, c, beans, args);
				List<CmiGoodsVariety> supers = new ArrayList<CmiGoodsVariety>();
				for (CmiGoodsVariety t : vl) {
					for (CmiGoodsVariety s : vl) {
						if (s.getUuid() == t.getVarUp()) {
							s.getChildren().add(t);
							supers.add(t);
						}
					}
				}
				vl.removeAll(supers);
				ls = vl;
				break;
			case GOODS_BRAND:
				c = CmiGoodsBrand.class;
				break;
			case NEWS:
				c = CmiNewsType.class;
				break;
			case SINGLE:
				c = CmiSingleType.class;
				break;
			case AD_TYPE:
				c = CmiAdType.class;
				break;
			case AD_LOC:
				c = CmiAdLocation.class;
				break;
			case ORDER:
				c = CmiOrder.class;
				break;
			default:
				break;
			}
			if(!hasDone) {
				ls = service.queryForList(sql, c, beans, args);
			}
		} catch (Exception ex) {
			log4j.equals("Query Object List Error!Enum[" + e.getStatus() + "] :" + ex);
			ls = null;
		}
		return ls;
	}
	
}
